package cn.jiyun.controller;import cn.jiyun.common.config.Result;
import cn.jiyun.entity.XmNotification;
import cn.jiyun.service.IXmNotificationService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-27
 */
@RestController
@RequestMapping("/xm-platform/xm-notification")
public class XmNotificationController {

    @Autowired
    private IXmNotificationService xmNotificationService;

    @RequestMapping("/zhuangtai")
    public Result zhuangtai(Integer id,Integer status){
        XmNotification notification = new XmNotification();
        notification.setId(id);
        notification.setStatus(status);
        xmNotificationService.updateById(notification);
        return Result.ok("已读");
    }

    @RequestMapping("/findPage")
    public Result findPage(Integer pageNum,Integer pageSize,@RequestBody XmNotification xmNotification){
        Page page = xmNotificationService.findPage(pageNum,pageSize,xmNotification);
        return Result.ok(page);
    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        XmNotification xmNotification = xmNotificationService.getById(id);
        return Result.ok(xmNotification);
    }

    @RequestMapping("/findById2/{id}")
    public XmNotification findById2(@PathVariable Integer id){
        XmNotification xmNotification = xmNotificationService.getById(id);
        return xmNotification;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody XmNotification xmNotification){
        if (xmNotification.getId()==null){
            xmNotification.setReleaseTime(LocalDateTime.now());
            xmNotification.setCreationTime(LocalDateTime.now());
            xmNotification.setUpdatetime(LocalDateTime.now());
            xmNotification.setStatus(1);
            xmNotificationService.save(xmNotification);
            return Result.ok("添加成功！");
        }else {
            xmNotification.setUpdatetime(LocalDateTime.now());
            xmNotificationService.updateById(xmNotification);
            return Result.ok("修改成功！");
            }
    }

}
